package com.centaline.androidsalesblog.rx.request;

import com.android.volley.VolleyError;
import com.centaline.androidsalesblog.api.usercenter.UpdateCollectApi;
import com.centaline.androidsalesblog.model.responseobject.SimpleUserCenterRo;
import com.centanet.framework.interfaces.IResponseListener;

import rx.Observable;
import rx.Subscriber;

/**
 * 取消收藏
 * Created by guilin on 16/3/21.
 */
final class RequestCanelCollectOnSubscribe implements Observable.OnSubscribe<SimpleUserCenterRo> {

    private final Class<?> tag;
    private final String collectId;

    public RequestCanelCollectOnSubscribe(Class<?> tag, String collectId) {
        this.tag = tag;
        this.collectId = collectId;
    }

    @Override
    public void call(final Subscriber<? super SimpleUserCenterRo> subscriber) {
        UpdateCollectApi updateCollectApi = new UpdateCollectApi(tag, SimpleUserCenterRo.class, new IResponseListener<SimpleUserCenterRo>() {
            @Override
            public void onResponse(SimpleUserCenterRo simpleUserCenterRo) {
                if (!subscriber.isUnsubscribed()) {
                    subscriber.onNext(simpleUserCenterRo);
                }
                subscriber.onCompleted();
            }

            @Override
            public void onErrorResponse(VolleyError error) {
                subscriber.onError(error);
            }
        });
        updateCollectApi.setCollectID(collectId);
        updateCollectApi.setIsDel(1);
        updateCollectApi.startRequest();
    }
}
